package com.javen.oauthserver.service.impl;

import com.javen.oauthserver.dao.UserMapper;
import com.javen.oauthserver.domain.SysRole;
import com.javen.oauthserver.domain.SysUser;
import com.javen.oauthserver.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description: com.javen.oauthserver.service.impl
 * @Author: tujw@netinnet.cn
 * @Date: 2023/9/19 17:08
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = userMapper.findByUsername(username);
        SysRole sysRole = new SysRole();
        sysRole.setId(1);
        sysRole.setRoleName("ADMIN");
        sysRole.setRoleDesc("ADMIN");
        List<SysRole> roles = new ArrayList<>();
        roles.add(sysRole);
        sysUser.setRoles(roles);
        return sysUser;
    }
}
